package com.adtec.base.cloud.wechatservice.wechatcloud.wechat.service.impl;

import com.adtec.base.cloud.commons.exception.CustomException;
import com.adtec.base.cloud.commons.exception.CustomExceptionType;
import com.adtec.base.cloud.commons.utils.HttpRequestUtil;
import com.adtec.base.cloud.persistence.wechat.mapper.MyWechatMapper;
import com.adtec.base.cloud.persistence.wechat.mapper.WechatEnterpriseMapper;
import com.adtec.base.cloud.persistence.wechat.model.WechatEnterprise;
import com.adtec.base.cloud.security.jwt.utils.GetUserId;
import com.adtec.base.cloud.wechatservice.wechatcloud.wechat.service.EnterpriseService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class EnterpriseServiceImpl implements EnterpriseService {

    @Resource
    private WechatEnterpriseMapper enterpriseMapper;

    @Resource
    private MyWechatMapper myWechatMapper;

    @Override
    public void addEnterprise(WechatEnterprise wechatEnterprise) {
        if (StringUtils.isBlank(wechatEnterprise.getEnterprise())) {
            throw new CustomException(CustomExceptionType.USER_INPUT_ERROR, "企业名称不能为空");
        }
        if (StringUtils.isBlank(wechatEnterprise.getCorpid())) {
            throw new CustomException(CustomExceptionType.USER_INPUT_ERROR, "Corpid不能为空");
        }
        enterpriseMapper.insert(wechatEnterprise);
    }

    @Override
    public void updateEnterprise(WechatEnterprise wechatEnterprise) {
        if (wechatEnterprise.getId() == null) {
            throw new CustomException(CustomExceptionType.USER_INPUT_ERROR, "操作必须带主键");
        } else {
            enterpriseMapper.updateById(wechatEnterprise);
        }
    }

    @Override
    public void deleteEnterprise(Long id) {
        if (id == null) {
            throw new CustomException(CustomExceptionType.USER_INPUT_ERROR, "操作必须带主键");
        } else {
            enterpriseMapper.deleteById(id);
        }
    }

    @Override
    public List<WechatEnterprise> query(String enterpriseName) {
        return myWechatMapper.selectEnterprise(enterpriseName);
    }
}
